package com.edu.storage.controller;


import com.edu.storage.entity.TStorage;
import com.edu.storage.service.ITStorageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author dingchengyu
 * @since 2022-05-13
 */
@RestController
@RequestMapping("/storage")
public class TStorageController {

    @Autowired
    private ITStorageService storageService;

    @RequestMapping("/list")
    public List<TStorage> list(){
        return storageService.list();
    }

    /**
     * 查询商品价格
     *
     * @param commodityCode 商品编码
     * @return
     */
    @RequestMapping("/selectPrice")
    public Long selectPrice(@RequestParam("commodityCode") String commodityCode) {
        return storageService.selectPrice(commodityCode);
    }

    /**
     * 扣减库存
     *
     * @param commodityCode 商品编码
     * @param count         商品数量
     * @return
     */
    @RequestMapping("/deductStorage")
    public int deductStorage(@RequestParam("commodityCode") String commodityCode,
                             @RequestParam("count") int count) {
        return storageService.deductStorage(commodityCode, count);
    }
}
